import QtQuick 1.0

Item {
    id: root

    property Constants constants: Constants {}
    property alias blur : blurScreen
    property alias commonDialog : commonDialog

    /*!
      Closes all dialogs.
    */
    function closeDialog()
    {
        console.debug("root.closeDialog()");
        root.blur.state = "off";
        commonDialog.opacity = 0;
        driveSelectionDialog.opacity = 0;
    }

    TitleBar {
        id: titleBar
        height: parent.height * constants.titleBarRelativeHeight
        anchors.top: parent.top
        z: 1
    }

    BlurScreen {
        id: blurScreen
        anchors.fill: parent
        anchors.topMargin: parent.height * constants.titleBarRelativeHeight
        z: 2
    }

    Dialog {
        id: commonDialog
        width: root.width * constants.dialogRelativeWidth
        height: root.height / 3
        anchors.centerIn: parent
        z: 4
        opacity: 0.0;
        title: "Hal says"
        information: "I'm afraid I can't do that, Dave."
    }

    DriveSelectionDialog {
        id: driveSelectionDialog
        width: root.width * constants.dialogRelativeWidth
        height: constants.dialogTitleHeight +
                (constants.fileListModelItemHeight +
                 constants.defaultLayoutSpacing) *
                driveModel.rowCount +
                constants.defaultLayoutSpacing * 2
        anchors.centerIn: parent
        z: 3
        opacity: 0.0;
    }

    Rectangle {
        id: viewContainer
        anchors.fill: parent
        anchors.topMargin: parent.height * constants.titleBarRelativeHeight

        gradient: Gradient {
            GradientStop { position: 0.0; color: constants.defaultBackgroundColor }
            GradientStop { position: 1.0; color: constants.darkBackgroundColor }
        }

        Item {
            anchors.fill: parent

            MainView {
                id: mainView
                width: parent.width
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.bottomMargin: parent.height *
                                      constants.navigationBarRelativeHeight +
                                      constants.defaultMargin
                color: constants.transparentColor
            }

            ViewLoader {
                id: fileBrowserView
                keepLoaded: true
                viewSource: "FileBrowserView.qml"
            }

            ViewLoader {
                id: infoView
                keepLoaded: false
                viewSource: "InfoView.qml"
            }
        }
    }

    NavigationBar {
        id: navigationBar
        width: parent.width
        height: parent.height * constants.navigationBarRelativeHeight * 2
        color: constants.transparentColor
        opacity: 0.0 // On startup
        hidden: viewSwitcher.currentView == fileBrowserView ? true : false;

        Behavior on opacity {
            NumberAnimation { duration: root.constants.shortAnimationDuration; }
        }
    }

    ViewSwitcher {
        id: viewSwitcher
    }

    Component.onCompleted: {
        viewSwitcher.currentView = mainView;
        startupTimer.start();
    }

    Timer {
        id: startupTimer
        interval: 400;
        running: false;
        repeat: false

        onTriggered: {
            navigationBar.opacity = 1.0;
        }
    }
}

// End of file.
